#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=,MAXM=;
int n,m,cnt,match[MAXN],head[MAXN],ans;
bool vis[MAXN];
struct edge
{
	int v,next;
}e[MAXM*2];
void addedge(int x,int y)
{
	e[++cnt]=(edge){y,head[x]};
	head[x]=cnt;
	return;
}
bool Hungary(int u)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v;
		if(!vis[v])
		{
			vis[v]=true;
			if(!match[v]||Hungary(match[v]))
			{
				match[v]=u;
				return true;
			}
		}
	}
	return false;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(x,y);
	}
	for(int i=1;i<=n;i++)
	{
		memset(vis,false,sizeof(vis));
		if(Hungary(i))ans++;
	}
	printf("%d\n",ans);
	return 0;
}
